/*
 Copyright 2012 Ronald Pablos 

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package org.bn.metadata.constraints;

import java.util.Collection;
import java.util.LinkedList;
import org.bn.coders.ConstraintException;

/**
 *
 * @author Ronald
 */
public class ASN1MultiConstraintMetadata implements IASN1ConstraintMetadata {

    Collection<IASN1ConstraintMetadata> collection;

    public ASN1MultiConstraintMetadata() {
        this(new LinkedList<IASN1ConstraintMetadata>());
    }
    public ASN1MultiConstraintMetadata(Collection<IASN1ConstraintMetadata> collection) {
        this.collection = collection;
    }
    
    public Collection<IASN1ConstraintMetadata> getCollection() {
        return collection;
    }
    
    @Override
    public boolean checkValue(Object value) throws ConstraintException {
        IASN1ConstraintMetadata[] ca = collection.toArray(new IASN1ConstraintMetadata[0]);
        for (IASN1ConstraintMetadata element: ca) {
            if (!element.checkValue(value))
                return false;
        }
        return true;
    }

    @Override
    public boolean checkLength(long len) throws ConstraintException {
        IASN1ConstraintMetadata[] ca = collection.toArray(new IASN1ConstraintMetadata[0]);
        for (IASN1ConstraintMetadata element: ca) {
            if (!element.checkLength(len))
                return false;
        }
        return true;
    }
    
}
